﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.ComponentModel;

namespace IKYSWeb.UserControls
{
    public partial class Ascx_ZamanAralik : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                for (int i = 0; i < 24; i++)
                {
                    if (i < 10)
                    {
                        ddlSonSaat.Items.Add(new ListItem("0" + i.ToString(), i.ToString()));
                        ddlBasSaat.Items.Add(new ListItem("0" + i.ToString(), i.ToString()));
                    }
                    else
                    {
                        ddlSonSaat.Items.Add(new ListItem(i.ToString(), i.ToString()));
                        ddlBasSaat.Items.Add(new ListItem(i.ToString(), i.ToString()));
                    }


                }
                for (int i = 0; i < 60; i++)
                {
                    if (i < 10)
                    {
                        ddlBasDakika.Items.Add(new ListItem("0" + Convert.ToInt32(i).ToString(), Convert.ToInt32(i).ToString()));
                        ddlSonDakika.Items.Add(new ListItem("0" + Convert.ToInt32(i).ToString(), Convert.ToInt32(i).ToString()));
                    }
                    else
                    {
                        ddlBasDakika.Items.Add(new ListItem(Convert.ToInt32(i).ToString(), Convert.ToInt32(i).ToString()));
                        ddlSonDakika.Items.Add(new ListItem(Convert.ToInt32(i).ToString(), Convert.ToInt32(i).ToString()));
                    }


                }
            }
        }

        protected string sDizilim = "";

        public enum DizilimTuru
        {
            Yatay = 0,
            Dikey = 1
        }

        public DizilimTuru Dizilim
        {
            set
            {
                if (value == DizilimTuru.Yatay)
                {
                    sDizilim = "";
                }
                else
                {
                    sDizilim = "<br /><br />";
                }
            }
        }


        public DateTime BasZaman
        {
            get
            {
                if (txtBasTarih.Text != "")
                    return Convert.ToDateTime(txtBasTarih.Text).AddHours(Convert.ToInt32(ddlBasSaat.SelectedValue)).AddMinutes(Convert.ToInt32(ddlBasDakika.SelectedValue));
                else
                    return DateTime.MinValue;
            }
            set
            {
                txtBasTarih.Text = (value != DateTime.MinValue) ? value.ToShortDateString() : "";
                ddlBasSaat.SelectedValue = value.Hour.ToString();
                ddlBasDakika.SelectedValue = value.Minute.ToString();
            }
        }

        public bool BasZamanReadOnly
        {
            set
            {
                txtBasTarih.ReadOnly = value;
                txtBasTarih.CssClass = (value ? "" : "tarih1");
                ddlBasSaat.Enabled = !value;
                ddlBasDakika.Enabled = !value;

            }
        }

        public bool BasZamanAllowEmpty
        {
            set { rfvBasTarih.Enabled = !value; }
        }


        public DateTime SonZaman
        {
            get
            {
                if (txtSonTarih.Text != "")
                    return Convert.ToDateTime(txtSonTarih.Text).AddHours(Convert.ToInt32(ddlSonSaat.SelectedValue)).AddMinutes(Convert.ToInt32(ddlSonDakika.SelectedValue));
                else
                    return DateTime.MinValue;
            }
            set
            {
                txtSonTarih.Text = (value != DateTime.MinValue) ? value.ToShortDateString() : "";
                ddlSonSaat.SelectedValue = value.Hour.ToString();
                ddlSonDakika.SelectedValue = value.Minute.ToString();
            }
        }

        public bool SonZamanReadOnly
        {
            set
            {
                txtSonTarih.ReadOnly = value;
                txtSonTarih.CssClass = (value ? "" : "tarih2");
                ddlSonSaat.Enabled = !value;
                ddlSonDakika.Enabled = !value;
            }
        }

        public bool SonZamanAllowEmpty
        {
            set { rfvSonTarih.Enabled = !value; }
        }


        public void Clear()
        {
            txtBasTarih.Text = "";
            txtSonTarih.Text = "";
            ddlBasSaat.SelectedIndex = 0;
            ddlBasDakika.SelectedIndex = 0;
            ddlSonSaat.SelectedIndex = 0;
            ddlSonDakika.SelectedIndex = 0;
        }

        public string ValidationGroup
        {
            set
            {
                rfvBasTarih.ValidationGroup = value;
                rfvSonTarih.ValidationGroup = value;
            }
        }

        public string BasZamanHataMesaji
        {
            set { rfvBasTarih.ErrorMessage = value; }
        }

        public string SonZamanHataMesaji
        {
            set { rfvSonTarih.ErrorMessage = value; }
        }
        public Unit BasZamanWidth
        {
            set { txtBasTarih.Width = value; }
        }
        public Unit SonZamanWidth
        {
            set { txtSonTarih.Width = value; }
        }

    }
}